﻿namespace IBTrader.Indicator.Channel
{
    using IBTrader.Modules.Read;
    using IBTrader.Charts;

    /// <summary>
    /// Measures the distance, or difference, between the upper band and the lower band. 
    /// BandWidth decreases as Bollinger Bands narrow and increases as Bollinger Bands widen. 
    /// Because Bollinger Bands are based on the standard deviation, falling BandWidth reflects decreasing volatility and rising BandWidth reflects increasing volatility.
    /// </summary>
    class BollingerBandWidth : Base
    {
        private readonly BollingerBand bollingerBand;
        public BollingerBandWidth(Worker worker, int interval = 60, float factor = 2f) : base(worker, new ChartArgs { Group = 1 })
        {
            Line up = null;
            bollingerBand = new BollingerBand(worker, interval, interval, factor);
            bollingerBand.Up += (_, line) => up = line;
            bollingerBand.Down += (_, line) => OnHit(line, up.Price - line.Price);
        }
        public override void Add(object sender, Line line)
        {
            bollingerBand.Add(sender, line);
        }
    }
}
